﻿(function () {

    //pre-define bob.utils namespace functions.

    var isUndefined = function (obj) {
        return (typeof (obj) === 'undefined');
    };

    var isNull = function (obj) {
        return (obj === null);
    };

    var isUndefinedOrNull = function (obj) {
        return (isUndefined(obj) || isNull(obj));
    };

    //pre-define bob.ns namespace functions.

    var setNs = function (ns, extension) {
        if (!ns) {
            throw new Error('Wrong argument: ns.');
        }

        var nsParts = ns.indexOf('.') >= 0 ? ns.split('.') : [ns];
        var parentNs = window;
        for (var i = 0; i < nsParts.length; i++) {
            var childNs = nsParts[i];
            if (isUndefinedOrNull(parentNs[childNs])) {
                parentNs[childNs] = {};
            }
            parentNs = parentNs[childNs];
        }

        if (!isUndefinedOrNull(extension)) {
            //extension argument is present.
            for (var member in extension) {
                parentNs[member] = extension[member];
            }
        }

        return parentNs;
    };

    setNs('bob.utils', {

        isUndefined: isUndefined,

        isNull: isNull,

        isUndefinedOrNull: isUndefinedOrNull

    });

    setNs('bob.ns', {

        setNs: setNs

    });

})();
